package com.crm.system.service.impl.sys;

import com.crm.common.model.DhPageInfo;
import com.crm.common.util.CommonUtils;
import com.crm.model.entity.sys.UserAccount;
import com.crm.model.entity.sys.permissionManagement.SysIssueInvoice;
import com.crm.model.vo.sys.IssueInvoiceVO;
import com.crm.service.sys.permissionManagement.IssueInvoiceDbService;
import com.crm.system.service.sys.IssueInvoiceService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @Author:chaifuyou
 * @Date: 2021/7/22 13:58
 */
@Service
public class IssueInvoiceServiceImpl implements IssueInvoiceService {

    @Autowired
    private IssueInvoiceDbService issueInvoiceDbService;

    /**
     * 分页查询分公司开票列表
     * @param pageIndex
     * @param pageSize
     * @param companyName
     * @return
     */
    @Override
    public DhPageInfo<IssueInvoiceVO> selectIssueInvoiceList(Integer pageIndex, Integer pageSize, String companyName) {
        UserAccount userAccount = (UserAccount) SecurityUtils.getSubject().getPrincipal();//当前登录人信息
        if (pageIndex != null && pageSize != null) {
            PageHelper.startPage(pageIndex, pageSize);
        }
        List<IssueInvoiceVO> customerList = issueInvoiceDbService.selectIssueInvoiceList(companyName);
        PageInfo<IssueInvoiceVO> pageInfo = new PageInfo<IssueInvoiceVO>(customerList);
        return new DhPageInfo<IssueInvoiceVO>(pageInfo, customerList);
    }

    /**
     * 增加分公司开票公司
     * @param sysIssueInvoice
     */
    @Override
    public void addCompanyIssueInvoice(SysIssueInvoice sysIssueInvoice) {
        UserAccount userAccount = (UserAccount) SecurityUtils.getSubject().getPrincipal();//当前登录人信息
        sysIssueInvoice.setIssueInvoiceId(CommonUtils.getGUID());
        sysIssueInvoice.setCreatePeopleId(userAccount.getAccountId());
        sysIssueInvoice.setCreateTm(new Date());
        issueInvoiceDbService.addCompanyIssueInvoice(sysIssueInvoice);
    }

    /**
     * 删除分公司开票信息
     * @param companyId
     */
    @Override
    public void delCompanyIssueInvoice(String companyId) {
        issueInvoiceDbService.delCompanyIssueInvoice(companyId);
    }

    /**
     * 删除开票信息
     * @param issueInvoiceId
     */
    @Override
    public void delIssueInvoice(String issueInvoiceId) {
        issueInvoiceDbService.delIssueInvoice(issueInvoiceId);
    }

    /**
     * 根据分公司查询开票公司列表
     * @param pageIndex
     * @param pageSize
     * @param companyId
     * @return
     */
    @Override
    public DhPageInfo<IssueInvoiceVO> selectInvoiceCompanyList(Integer pageIndex, Integer pageSize, String companyId) {
        if (pageIndex != null && pageSize != null) {
            PageHelper.startPage(pageIndex, pageSize);
        }
        List<IssueInvoiceVO> customerList = issueInvoiceDbService.selectInvoiceCompanyList(companyId);
        PageInfo<IssueInvoiceVO> pageInfo = new PageInfo<IssueInvoiceVO>(customerList);
        return new DhPageInfo<IssueInvoiceVO>(pageInfo, customerList);
    }
}
